home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 111_01 / chop.c < prev    next >
Text File  |  1985-08-19  |  2KB  |  75 lines

  1. /*
  2. HEADER:        ;
  3. TITLE:        Chop;
  4. VERSION:    1.1;
  5. DATE:        10/27/1985;
  6.  
  7. DESCRIPTION:    "Removes sectors from the beginning of a file,
  8.         and creates a new file containing the remaining data.";
  9.  
  10. KEYWORDS:    File, utility;
  11. SYSTEM:        CP/M-80;
  12. FILENAME:    CHOP.C;
  13. AUTHORS:    Unknown;
  14. COMPILERS:    BDS C;
  15. */
  16. /************************************************************************
  17.  
  18.     Ver. 1.0: Author and date unknown.
  19.     Version 1.1, October 27, 1985:
  20.         Sign-on message modified to provide instructions
  21.         if the user formats the command line incorrectly.
  22.         John M. Smith, CUG librarian, Utilities IV diskette.
  23.  
  24.     Usage: A>CHOP file1 file2 n
  25.  
  26.         file1 is input, file2 is created, and
  27.         "n" is the number of records to "chop".
  28.  
  29. *************************************************************************/
  30.  
  31.  int nskip, recnum;
  32.  int infd, outfd;
  33.  char buf[128];
  34.  
  35. main(argc,argv)
  36. int argc; char *argv[];
  37. {
  38.  
  39.  puts("\nFile Chopper, V1.1\n");
  40.  
  41.  if (argc != 4)
  42.   { puts("Removes sectors from the front of a file.\n\n");
  43.     puts("Usage: CHOP file1 file2 n\n\n");
  44.     puts("file1 is input, file2 is created, and\n");
  45.     puts("n is the number of sectors to remove.\n");
  46.     exit(); }
  47.  
  48.  if ((nskip = atoi(argv[3])) == 0)
  49.   { puts("No records to skip\n"); exit(); }
  50.  
  51.  /* open files */
  52.  
  53.  if ((infd = open(argv[1],0)) == -1)
  54.   { printf("%s%s","File not found: ",argv[1]); exit(); }
  55.  
  56.  if ((outfd = creat(argv[2])) == -1)
  57.   { printf("%s%s","Cannot create: ",argv[2]); exit(); }
  58.  
  59.  printf("Skipping %u records\n", nskip);
  60.  for (recnum = 0; recnum < nskip; recnum++)
  61.   { if (read(infd,buf,1) <= 0)
  62.      { printf("%s %u","File read error at record",recnum); exit(); }
  63.   }
  64.  
  65.  while (read(infd,buf,1) > 0)
  66.   { if (write(outfd,buf,1) == -1)
  67.      { printf("Output file error at record %u",recnum); exit(); }
  68.   }
  69.  
  70.  puts("Done\n");
  71.  
  72.  close(outfd);
  73.  
  74.  }
  75.